package com.zhongyu.user.consumer.service.impl;

import com.zhongyu.comm.pojo.LinkUser;
import com.zhongyu.comm.pojo.User;
import com.zhongyu.user.consumer.client.LinkUserClient;
import com.zhongyu.user.consumer.client.UserClient;
import com.zhongyu.user.consumer.service.LinkUserService;
import com.zhongyu.user.consumer.vo.LinkUserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service("linkUserService")
public class LinkUserServiceImpl implements LinkUserService {

    @Resource
    private UserClient userClient;

    @Resource
    private LinkUserClient linkUserClient;

    @Override
    public List<LinkUserVo> queryLinkUser(String token) {
      User user=userClient.getUser(token);
     List<LinkUser> list=linkUserClient.findLinkUser(user.getId());
   return   list.stream().map(linkUser -> {
         LinkUserVo linkUserVo=new LinkUserVo();
         BeanUtils.copyProperties(linkUser,linkUserVo);
         linkUserVo.setLinkId(linkUser.getId());
         return linkUserVo;
     }).collect(Collectors.toList());

    }
}
